import { CzmES3DTileset } from "@czmSrc/CzmObjects";
import { RotationEditing } from "@czmSrc/EditingSystem/base";
import { ESCesiumViewer } from "@czmSrc/ESCesiumViewer";
import { ES3DTileset, ESJEditingMode, ESSceneObject } from "earthsdk3";
import { bind, nextAnimateFrame } from "xbsj-base";
import { BaseEditingWrapper } from "./BaseEditingWrapper";
export class RotationEditingWrapper extends BaseEditingWrapper {
    static readonly type = this.registerEditing("ESCesiumViewer", ESJEditingMode.Rotation, this);
    constructor(sceneObject: ESSceneObject, czmViewer: ESCesiumViewer) {
        super(sceneObject, czmViewer, true);
        const rotationEditing = this.currentEditing = this.ad(new RotationEditing(czmViewer));
        rotationEditing.rotation = [90, 0, 0];
        this.ad(rotationEditing.enabledChanged.don((newVal) => {
            !newVal && this.ad(nextAnimateFrame(() => {
                this.destroy();
            }));
        }));
        do {
            if (sceneObject instanceof ES3DTileset) {
                const czmES3DTileset = czmViewer.getCzmObject(sceneObject) as CzmES3DTileset;
                this.ad(bind([rotationEditing, 'position'], [czmES3DTileset.czm3DTiles, 'position']));
                this.ad(bind([rotationEditing, 'selfRotation'], [sceneObject, 'rotation']));
                break;
            }
            if (Reflect.has(sceneObject, 'position') && Reflect.has(sceneObject, 'rotation')) {
                //@ts-ignore
                this.ad(bind([rotationEditing, 'position'], [sceneObject, 'position']));
                //@ts-ignore
                this.ad(bind([rotationEditing, 'selfRotation'], [sceneObject, 'rotation']));
                break;
            }
            this.supportEditing = false;
        } while (false);
    }
}